package com.eva.admin.api.system;

import com.eva.framework.common.api.BaseController;
import com.eva.admin.dao.system.icon.dto.QuerySystemIconDTO;
import com.eva.admin.biz.system.icon.dto.CreateSystemIconDTO;
import com.eva.admin.biz.system.icon.dto.UpdateSystemIconDTO;
import com.eva.dao.system.model.SystemIcon;
import com.eva.admin.dao.system.icon.vo.SystemIconVO;
import com.eva.admin.biz.system.icon.SystemIconBiz;
import com.eva.framework.common.model.ApiResponse;
import com.eva.framework.common.model.PageData;
import com.eva.framework.common.model.PageWrap;
import com.eva.framework.rbac.authorize.ContainAnyPermissions;
import com.eva.framework.rbac.authorize.ContainPermissions;
import com.eva.service.system.SystemIconService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "系统图标")
@Slf4j
@RestController
@RequestMapping("/system/icon")
public class SystemIconController extends BaseController {

    @Resource
    private SystemIconBiz systemIconBiz;

    @Resource
    private SystemIconService systemIconService;

    @ApiOperation("创建")
    @PostMapping("/create")
    @ContainPermissions("system:icon:create")
    public ApiResponse<?> create(@RequestBody CreateSystemIconDTO dto) {
        systemIconBiz.create(dto);
        return ApiResponse.success(null);
    }

    @ApiOperation("根据ID删除")
    @GetMapping("/delete/{id}")
    @ContainPermissions("system:icon:delete")
    public ApiResponse<?> deleteById(@PathVariable Integer id) {
        systemIconBiz.deleteById(id);
        return ApiResponse.success(null);
    }

    @ApiOperation("根据ID批量删除")
    @GetMapping("/delete/batch")
    @ContainPermissions("system:icon:delete")
    public ApiResponse<?> deleteByIdInBatch(@RequestParam String ids) {
        systemIconBiz.deleteByIdInBatch(this.getIdList(ids));
        return ApiResponse.success(null);
    }

    @ApiOperation("根据ID修改")
    @PostMapping("/updateById")
    @ContainPermissions("system:icon:update")
    public ApiResponse<?> updateById(@RequestBody UpdateSystemIconDTO dto) {
        systemIconBiz.updateById(dto);
        return ApiResponse.success(null);
    }
    
    @ApiOperation("分页查询")
    @PostMapping("/page")
    @ContainPermissions({"system:icon:query"})
    public ApiResponse<PageData<SystemIconVO>> findPage(@RequestBody PageWrap<QuerySystemIconDTO> pageWrap) {
        return ApiResponse.success(systemIconBiz.findPage(pageWrap));
    }

    @ApiOperation("查询所有")
    @GetMapping("/all")
    @ContainAnyPermissions({
            "system:icon:query",
            "system:menu:create",
            "system:menu:update"
    })
    public ApiResponse<List<SystemIcon>> findAll() {
        return ApiResponse.success(systemIconService.findAll());
    }
}
